**************************************************************************************************************************************************
****************************** Wealth-Income Ratios in Free Market Capitalism: Switzerland, 1900-2020 ********************************************
**************************************************************************************************************************************************

clear all
set more off
set scheme s1color  
cap set scheme mygraphs

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: January, 25 2023

*** set this path to the current directory
*** global mypath "C:\Users\EBaselgia\Dropbox\WIR_project\Publication_process\replication"

*** EXTENSION C: CROSS-COUNTRY EVIDENCE ON WIR AND HOUSING PRICES ***


* PLOT DATA FROM REGRESSIONS OF WIR ON STOCK PRICES AND REAL ESTATE PRICES*
/*  countries: CH, US, FR, IT, SW, DE
	stock market indices: DowJones, DAX, Nikkei225, SMI, S&P100 Global, MSCI World
	country share price indices from OECD:  CH, US, FR, IT, SW, DE, GB, EA19, JP
	housing price indices from OECD: CH, US, FR, IT, SW, DE, GB, EA19
	WIR: CH, US, FR, IT, SW, DE, GB
*/


* * * READ DATA * * * 
cd "$mypath/final_data/"
use "house_price_final_data.dta", clear

mkdir "$mypath/output/extension_C/"
cd "$mypath/output/extension_C/"


**** rename all variables to capital country codes letters to create figures

foreach var in pWIR houseP_real_cpi shareP_real_cpi{

	rename au_`var' AU_`var'
	rename ca_`var' CA_`var'
	rename ch_`var' CH_`var'
	rename de_`var' DE_`var'
	rename es_`var' ES_`var'
	rename fr_`var' FR_`var'
	rename gb_`var' GB_`var'
	rename it_`var' IT_`var'
	rename jp_`var' JP_`var'
	rename no_`var' NO_`var'
	rename se_`var' SE_`var'
	rename us_`var' US_`var'
}




* * * PLOT WIR AND PRICE INDICES SINCE 1995 * * * 
** findit grc1leg2 // install this ado to have a common legend in combined graph


* * * REAL HOUSING PRICES * * *
// save correlation coefficients to put on plot
preserve
drop if year < 1995

local a "CH_pWIR DE_pWIR FR_pWIR IT_pWIR SE_pWIR US_pWIR"
local b "CH_houseP_real_cpi DE_houseP_real_cpi FR_houseP_real_cpi IT_houseP_real_cpi SE_houseP_real_cpi US_houseP_real_cpi"

local n = 0
local myline
forval i = 1/6 {
local aa : word `i' of `a'
local bb : word `i' of `b'
local n= `n'+1

pwcorr `aa' `bb' if year >= 1995 , sig
local cor_`n' = `r(rho)'
local cor_`n' : di %3.2f `cor_`n''
display `cor_`n''

}
restore



// re-label real estate price indices
foreach var in CH_houseP_real_cpi DE_houseP_real_cpi FR_houseP_real_cpi IT_houseP_real_cpi SE_houseP_real_cpi US_houseP_real_cpi {
label var `var' "Real estate price index"
}

// save country names for titles +
local n = 0
foreach var in CH_pWIR DE_pWIR FR_pWIR IT_pWIR SE_pWIR US_pWIR{
local n= `n'+1
local title`n' "`: variable label `var''"
}

// real estate prices +  
local a "CH_pWIR DE_pWIR FR_pWIR IT_pWIR SE_pWIR US_pWIR"
local b "CH_houseP_real_cpi DE_houseP_real_cpi FR_houseP_real_cpi IT_houseP_real_cpi SE_houseP_real_cpi US_houseP_real_cpi"


local n = 0
local myline
forval i = 1/6 {
local aa : word `i' of `a'
local bb : word `i' of `b'
local n= `n'+1

sum `bb' if year >= 1995
local min_`n' = round(`r(min)' + 2 , 5)
local min_`n' : di %3.0f `min_`n''
display `min_`n''

local myline`n' (line `bb' year if year >=1995)
}




label var AU_shareP_real_cpi "Australia"
label var CA_shareP_real_cpi "Canada"
label var CH_shareP_real_cpi "Switzerland"
label var DE_shareP_real_cpi "Germany"
label var ES_shareP_real_cpi "Spain"
label var FR_shareP_real_cpi "France"
label var GB_shareP_real_cpi "United Kingdom"
label var IT_shareP_real_cpi "Italy"
label var JP_shareP_real_cpi "Japan"
label var NO_shareP_real_cpi "Norway"
label var SE_shareP_real_cpi "Sweden" 
label var US_shareP_real_cpi "United States"

           



set scheme s1color
local n = 0
foreach var in CH DE SE IT FR US{
local n= `n'+1

tw  (line `var'_houseP_real_cpi year if year>=1995, yaxis(1) lcolor(black) lpattern() lwidth(medthick)  ) ///
	(connect `var'_pWIR year if year>=1995, yaxis(2) lcolor(red*1.1) msize(*0.6) mcolor(red*1.1) msymb(O) lwidth(medthick) ) ///
	, title(`: variable label `var'_shareP_real_cpi', size(normalsize)) legend(off) ytitle(Housepriceindex - Real) xtitle("") xlabel(2000 "2000"  2010 "2010"  2020 "2020") /// 
	ylab(, grid) ytitle("Real estate price index (2010=100)", axis(1) size(medsmall)) ytitle("Wealth-income ratio", axis(2) size(medsmall)) ///
	text(`min_`n'' 2010 "{&rho}=`cor_`n''", place(e)) xsize(7) ysize(5) ysc(titlegap(4)) plotregion(lcolor(black)) name(`var'_pWIR_fig_RR, replace)
}




// combine graphs
grc1leg2  CH_pWIR_fig_RR DE_pWIR_fig_RR SE_pWIR_fig_RR IT_pWIR_fig_RR FR_pWIR_fig_RR US_pWIR_fig_RR
graph export "Fig_append_C_2.pdf", as(pdf) replace



// grc1leg2 doesn't seem to take xsize and ysize, so the graph has to be edited manually to get a tall graph...
grc1leg2  CH_pWIR_fig_RR DE_pWIR_fig_RR SE_pWIR_fig_RR IT_pWIR_fig_RR FR_pWIR_fig_RR US_pWIR_fig_RR, cols(2) lsize(vsmall)

gr_edit style.editstyle declared_ysize(20) editcopy
gr_edit style.editstyle declared_xsize(16) editcopy
gr_edit legend.Edit , style(key_xsize(8)) keepstyles 

graph export "Fig_append_C_2.pdf", as(pdf) replace




///// Second set of countries: AU, GB, CA, ES, JP, NO

* * * REAL HOUSING PRICES * * *
// save correlation coefficients to put on plot
preserve
drop if year < 1995

local a "GB_pWIR AU_pWIR CA_pWIR ES_pWIR JP_pWIR NO_pWIR"
local b "GB_houseP_real_cpi AU_houseP_real_cpi CA_houseP_real_cpi ES_houseP_real_cpi JP_houseP_real_cpi NO_houseP_real_cpi"

local n = 0
local myline
forval i = 1/6 {
local aa : word `i' of `a'
local bb : word `i' of `b'
local n= `n'+1

pwcorr `aa' `bb' if year >= 1995 , sig
local cor_`n' = `r(rho)'
local cor_`n' : di %3.2f `cor_`n''
display `cor_`n''

}
restore



// re-label real estate price indices
foreach var in GB_houseP_real_cpi AU_houseP_real_cpi CA_houseP_real_cpi ES_houseP_real_cpi JP_houseP_real_cpi NO_houseP_real_cpi {
label var `var' "Real estate price index"
}

// save country names for titles +
local n = 0
foreach var in GB_pWIR AU_pWIR CA_pWIR ES_pWIR JP_pWIR NO_pWIR{
local n= `n'+1
local title`n' "`: variable label `var''"
}

foreach var in GB_pWIR AU_pWIR CA_pWIR ES_pWIR JP_pWIR NO_pWIR{
label var `var' "Net Private Wealth-Income Ratio"
}

// real estate prices +  
local a "GB_pWIR AU_pWIR CA_pWIR ES_pWIR JP_pWIR NO_pWIR"
local b "GB_houseP_real_cpi AU_houseP_real_cpi CA_houseP_real_cpi ES_houseP_real_cpi JP_houseP_real_cpi NO_houseP_real_cpi"


local n = 0
local myline
forval i = 1/6 {
local aa : word `i' of `a'
local bb : word `i' of `b'
local n= `n'+1

sum `bb' if year >= 1995
local min_`n' = round(`r(min)' + 2 , 5)
local min_`n' : di %3.0f `min_`n''
display `min_`n''

local myline`n' (line `bb' year if year >=1995)
}



set scheme s1color
local n = 0
foreach var in GB AU CA ES JP NO{
local n= `n'+1

tw  (line `var'_houseP_real_cpi year if year>=1995, yaxis(1) lcolor(black) lpattern() lwidth(medthick)  ) ///
	(connect `var'_pWIR year if year>=1995, yaxis(2) lcolor(red*1.1) msize(*0.6) mcolor(red*1.1) msymb(O) lwidth(medthick) ) ///
	, title(`: variable label `var'_shareP_real_cpi', size(normalsize)) legend(off) ytitle(Housepriceindex - Real) xtitle("") xlabel(2000 "2000"  2010 "2010"  2020 "2020") /// 
	ylab(, grid) ytitle("Real estate price index (2010=100)", axis(1) size(medsmall)) ytitle("Wealth-income ratio", axis(2) size(medsmall)) ///
	text(`min_`n'' 2011 "{&rho}=`cor_`n''", place(e)) xsize(7) ysize(5) ysc(titlegap(4)) plotregion(lcolor(black)) name(`var'_pWIR_fig_RR, replace)
}


// combine graphs
grc1leg2  GB_pWIR_fig_RR AU_pWIR_fig_RR CA_pWIR_fig_RR ES_pWIR_fig_RR JP_pWIR_fig_RR NO_pWIR_fig_RR
graph export "Fig_append_C_3.pdf", as(pdf) replace



// grc1leg2 doesn't seem to take xsize and ysize, so the graph has to be edited manually to get a tall graph...
grc1leg2  GB_pWIR_fig_RR AU_pWIR_fig_RR CA_pWIR_fig_RR ES_pWIR_fig_RR JP_pWIR_fig_RR NO_pWIR_fig_RR, cols(2) lsize(vsmall)

gr_edit style.editstyle declared_ysize(20) editcopy
gr_edit style.editstyle declared_xsize(16) editcopy
gr_edit legend.Edit , style(key_xsize(8)) keepstyles 

graph export "Fig_append_C_3.pdf", as(pdf) replace

	
	
	
	
************************************************************	
********** New Figures Year to Year changes ****************
************************************************************	
	

* * * READ DATA * * * 
cd "$mypath/final_data/"
use "house_price_final_data.dta", clear

cd "$mypath/output/extension_C/"


**** rename all variables to capital country codes letters to create figures
foreach var in pWIR houseP_real_cpi shareP_real_cpi{

	rename au_`var' AU_`var'
	rename ca_`var' CA_`var'
	rename ch_`var' CH_`var'
	rename de_`var' DE_`var'
	rename es_`var' ES_`var'
	rename fr_`var' FR_`var'
	rename gb_`var' GB_`var'
	rename it_`var' IT_`var'
	rename jp_`var' JP_`var'
	rename no_`var' NO_`var'
	rename se_`var' SE_`var'
	rename us_`var' US_`var'
}


drop if year < 1970
tsset year

** gen growth rates
foreach var in CH_pWIR DE_pWIR FR_pWIR GB_pWIR IT_pWIR SE_pWIR US_pWIR AU_pWIR CA_pWIR ES_pWIR JP_pWIR NO_pWIR ///
 AU_houseP_real_cpi CA_houseP_real_cpi CH_houseP_real_cpi DE_houseP_real_cpi ES_houseP_real_cpi FR_houseP_real_cpi ////
 GB_houseP_real_cpi IT_houseP_real_cpi JP_houseP_real_cpi NO_houseP_real_cpi SE_houseP_real_cpi US_houseP_real_cpi ////
 AU_shareP_real_cpi CA_shareP_real_cpi CH_shareP_real_cpi DE_shareP_real_cpi ES_shareP_real_cpi FR_shareP_real_cpi ///
 GB_shareP_real_cpi IT_shareP_real_cpi JP_shareP_real_cpi NO_shareP_real_cpi SE_shareP_real_cpi US_shareP_real_cpi MSCI_real_cpi{
	gen `var'_dif = (D.`var'/L.`var')*100
}



foreach var in CH DE FR GB IT SE US AU CA ES JP NO{
	
	label var `var'_pWIR_dif "Wealth-Income ratio, `var' (annual change in %)"
	label var `var'_houseP_real_cpi_dif "real house price index, `var' (annual change in %)"
	label var `var'_shareP_real_cpi_dif "real share price index, `var' (annual change in %)"
} 
 
 label var MSCI_real_cpi_dif "MSCI world index real (annual change in %)"
 
 
 	
// timeseries plots
foreach var in CH DE FR GB IT SE US AU CA ES JP NO{
tw  (connect MSCI_real_cpi_dif year, msymb(s) mcolor(gray) lcolor(gray) )    ///
	(connect `var'_shareP_real_cpi_dif year , msymb(t) mcolor(black) lcolor(black))  ///
	(connect `var'_houseP_real_cpi_dif year, msymb(d) mcolor(navy) lcolor(navy))  ///
	(connect `var'_pWIR_dif year, msymb(o) mcolor(red) lcolor(red) )  ///
, yline(0, lcolor(black)) ytitle("%-change") xtitle("") ylab(, grid) xlab(1970(10)2020, grid) ///
legend(row(4)) name(Fig_append_C_4_`var', replace)

graph export "Fig_append_C_4_`var'.pdf", as(pdf) replace
}
	
		
cd "$mypath/"
clear all
	
	
	

	
